using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;
using DIS_DAL_WS.Helpers;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class EmployeeDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
        public int IDRole { get; set; }
        [DataMember]
        public int IDRestaurant { get; set; }
        [DataMember]
        public string UserName { get; set; }
        [DataMember]
        public string Password { get; set; }
        [DataMember]
        public string FullName { get; set; }
        [DataMember]
        public RestaurantDTO Restaurant { get; set; }
        [DataMember]
        public RoleDTO Role { get; set; }

        public static EmployeeDTO Translate(Employee Entity)
        {
            if (Entity != null)
            {
                var dto = new EmployeeDTO
                {
                    ID = Entity.ID,
                    UserName = Entity.UserName,
                    Password = Entity.Password,
                    FullName = Entity.FullName,
                    Restaurant = RestaurantDTO.TranslateBase(Entity.Restaurant),
                    Role = RoleDTO.TranslateBase(Entity.Role)
                };
                if (Entity.IDRole != null)
                {
                    dto.IDRole = Entity.IDRole.Value;
                }
                else
                {
                    dto.IDRole = -1;
                }
                if (Entity.IDRestaurant != null)
                {
                    dto.IDRestaurant = Entity.IDRestaurant.Value;
                }
                else
                {
                    dto.IDRestaurant = -1;
                }
                return dto;
            }
            return null;
        }

        public static Employee Reverse(EmployeeDTO obj)
        {
            var entity = new Employee
            {
                ID = obj.ID,
                UserName = obj.UserName,
                Password = obj.Password,
                FullName = obj.FullName
            };
            GlobalVariables.Logger.Info("obj.IDRestaurant: " + obj.IDRestaurant);
            GlobalVariables.Logger.Info("obj.IDRole: " + obj.IDRole);
            if (obj.IDRestaurant != -1)
            {
                entity.IDRestaurant = obj.IDRestaurant;
            }
            if (obj.IDRole != -1)
            {
                entity.IDRole = obj.IDRole;
            }
            return entity;
        }

        public void UpdateEntity(ref Employee entity)
        {
            entity.UserName = UserName;
            entity.Password = Password;
            entity.FullName = FullName;

            if (IDRestaurant != -1)
            {
                entity.IDRestaurant = IDRestaurant;
            }
            if (IDRole != -1)
            {
                entity.IDRole = IDRole;
            }
        }
	}
}